package com.hrsoft.edi.stub;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.RandomUtil;
import com.hrsoft.edi.stub.consant.AppInfo;
import com.hrsoft.edi.stub.request.ReturnorderCreateRequest;
import com.qimen.api.DefaultQimenClient;
import com.qimen.api.QimenClient;
import com.qimen.api.response.ReturnorderCreateResponse;
import com.taobao.api.ApiException;
import lombok.extern.slf4j.Slf4j;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Slf4j
public class ReturnOrderCreateTest
{
    public static void create()
        throws ApiException
    {
        QimenClient client = new DefaultQimenClient(AppInfo.URL, AppInfo.APP_KEY, AppInfo.SECRET);
        ReturnorderCreateRequest createRequest=new ReturnorderCreateRequest();
        createRequest.setCustomerId(AppInfo.CUSTOMER_ID);
        createRequest.setVersion("2.0");
        ReturnorderCreateRequest.ReturnOrder returnOrder=new ReturnorderCreateRequest.ReturnOrder();
        returnOrder.setWarehouseCode(AppInfo.WAREHOUSE_CODE);
        returnOrder.setLogisticsCode("SF");
        returnOrder.setReturnOrderCode("27D" + RandomUtil.randomNumbers(15));
        returnOrder.setPreDeliveryOrderCode("DZLR" + RandomUtil.randomNumbers(15));
        returnOrder.setOrderConfirmTime(DateUtil.formatDateTime(new Date()));
        returnOrder.setOrderType("THRK");
        returnOrder.setExpressCode("123456987");
        ReturnorderCreateRequest.SenderInfo senderInfo=new ReturnorderCreateRequest.SenderInfo();
        senderInfo.setId("126704599851094016");
        senderInfo.setCompany("尚科宁家（中国）科技有限公司");
        senderInfo.setName("尚科宁家（中国）科技有限公司");
        senderInfo.setMobile("13218095873");
        senderInfo.setProvince("浙江省");
        senderInfo.setCity("杭州市");
        senderInfo.setArea("江干区");
        senderInfo.setDetailAddress("方君");
        createRequest.setReturnOrder(returnOrder);

        ReturnorderCreateRequest.OrderLine orderLine=new ReturnorderCreateRequest.OrderLine();
        orderLine.setItemCode("002");
        orderLine.setPlanQty(5L);
        orderLine.setInventoryType("ZP");
        orderLine.setOwnerCode(AppInfo.OWNER_CODE);

        List<ReturnorderCreateRequest.OrderLine> orderLines = new ArrayList<>();
        orderLines.add(orderLine);
        createRequest.setOrderLines(orderLines);
        createRequest.getReturnOrder().setSenderInfo(senderInfo);
        long time1 = System.currentTimeMillis();
        ReturnorderCreateResponse response = client.execute(createRequest);
        long time2 = System.currentTimeMillis();
        log.info("响应:{} ERP订单编码:{} wms仓储编码:{} 耗时:{}",response.getFlag(),returnOrder.getReturnOrderCode(),response.getReturnOrderId(),time2-time1);
    }
    public static void main(String[] args)

        throws ApiException
    {
        create();

    }
}
